/**
 * @param {number[]} candidates
 * @param {number} target
 * @return {number[][]}
 */
 var combinationSum = function(candidates, target) {
    let res =[],curr=[]
    candidates.sort((a,b)=>a-b)
    const tools = (starIndex,sum) =>{
        if(sum==target){
            res.push([...curr])
            return
        }
        if(sum>target){
            return 
        }
        for(let i=starIndex;i<candidates.length;i++){
            sum+=candidates[i]
            curr.push(candidates[i])
            tools(i,sum)
            sum-=candidates[i]
            curr.pop(candidates[i])
        }
    }
    tools(0,0)
    return res
};
console.log(combinationSum([2,3,6,7],7));